{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcfbase.css?v={$version}"/>
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<style>
.layui-table-cell {height:30px!important;}
</style>
<div class="layui-fluid" style="padding-bottom:83px;border:0;" id="LAY-component-layer-list">
<div class="layui-col-sm12">
    <div class="layui-card" style="box-shadow:0 0 0 0;">
      <div class="layui-tab layui-tab-brief" id="pcfsystem">
        <ul class="layui-tab-title" style="background-color:#f2f2f2;">
            <a href="{:url('/system.tools/index')}"><li>数据备份</li></a>
            <a href="{:url('/system.tools/restore')}"><li class="layui-this">数据还原</li></a>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <button data-type="batch_del" data-url="{:url('/system.tools/del')}" class="layui-btn icon-btn">批量删除</button>
                    </div>
                </div>
            </div>
            <table class="layui-table" id="tableUser" lay-filter="tableUser"></table>
        </div>
       </div>
    </div>
    <div class="pcfclear"></div>
</div>
</div>
<script type="text/html" id="tableBarUser">
    <a class="layui-btn layui-btn-primary layui-btn-sm" data-url="{:url('/system.tools/new_import')}" data-id="{{d.time}}" data-type="new_import">恢复</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" data-url="{:url('/system.tools/downFile')}" data-id="{{d.time}}" data-type="xaizai">下载</a>
    <a class="layui-btn layui-btn-sm" data-url="{:url('/system.tools/del')}" data-id="{{d.time}}" data-type="del">删除</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer','form','table','admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        // 渲染表格
        var insTb = table.render({
            elem: '#tableUser',
            url: "{:url('/system.tools/restore')}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type:'checkbox'},
                {field: 'basename', title: '文件名称',},
                {field: 'version', title: '系统版本'},
                {field: 'part', title: '卷号'},
                {field: 'size', title: '数据大小',align: 'center'},
                {field: 'showtime', title: '备份时间',align: 'center'},
                {align: 'center', toolbar: '#tableBarUser', title: '操作', minWidth: 250}
            ]]
        });
        $(document).on("click","#pcfsystem .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });
        /*触发事件*/
        var active = {
            // 恢复
            new_import: function(){
                var obj = this;
                var importtime = $(obj).attr('data-id');
                var url = $(obj).attr('data-url');
                layer.msg('确认还原数据吗？', {
                    btnAlign: 'c',
                    time: 0,
                    btn: ['确定', '取消'],
                    yes: function(index, layero){
                        layer.close(index);
                        layer.msg('还原中请勿刷新页面', {icon: 16,shade: 0.01});
                        $.ajax({
                            type: "POST",
                            url: url+"?time="+importtime,
                            dataType: 'json',
                            success: function (res) {
                                layer.closeAll();
                                if(res.code == 1){
                                    layer.msg(res.msg, {icon: 1, time:1000});
                                }else{
                                    layer.msg(res.msg, {icon: 2,time:1000});
                                }
                            },
                            error:function(){
                                layer.closeAll();
                                layer.msg("未知错误，操作中断！", {icon: 2,time:1000});
                            }
                        });
                    }
                });
            },            
            // 下载
            xaizai: function(){
                var obj = this;
                var url = $(obj).attr('data-url');
                var xaizaitime = $(obj).attr('data-id');
                window.location.href = url+"?time="+xaizaitime;
            },
            // 删除
            del: function(){
                delfun(this);
                return false;
            },
            // 批量删除
            batch_del: function(){
                var checkRows = table.checkStatus('tableUser');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据表', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.time;
                });
                batch_del(this, ids);
            }
        }
    });
</script>
</body>
</html>